<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title></title>
    <link rel="stylesheet" href="../../layui/css/layui.css">
    <link rel="stylesheet" href="../../layui/css/detail.css">
</head>

<body class="layui-layout-body">

    <div class="layui-body inner-body">

        <!-- 内容主体区域 -->
        <div style="padding: 15px">

            <fieldset class="layui-elem-field layui-field-title">
                <legend>
                    <button class="layui-btn layui-btn-sm">
                        <a href="../../pages/userManagement.html">返回</a>
                    </button>
                    添加用户
                </legend>
            </fieldset>

            <form class="layui-form" action="" lay-filter="addForm">
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">手机号</label>
                    <div class="layui-input-block" style="width:500px">
                        <input type="text" name="mobile" required lay-verify="phone" placeholder="请输入手机号" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <label class="layui-form-label">密码</label>
                <div class="layui-input-block"  style="width:500px;margin-bottom: 10px;" >
                        <input name="pwd" class="layui-input" type="password" placeholder="请输入密码" autocomplete="off" lay-verify="required">
                    </div>

                <label class="layui-form-label">管理员</label>
                        <input name="isAdmin" type="checkbox" value="true" lay-skin="switch" >
                        <div class="layui-unselect layui-form-switch layui-form-onswitch" lay-skin="_switch" >
                            <em></em><i></i>
                        </div>
                  
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button type="button" class="layui-btn" lay-submit="" lay-filter="user-addUser">添加用户</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    </div>
    </div>
    <script src="../../js/lodash.min.js"></script>
    <script src="../../layui/jquery-1.12.4.min.js"></script>
    <script src="../../layui/layui.js"></script>
    <script>

        //JavaScript代码区域
        layui.use(['form', "layer"], async function () {
            let form = layui.form;
            //提交
            form.on("submit(user-addUser)", async function (data) {
                console.log(data.field);
                await $.post("/api/User", data.field);
                layer.msg('添加用户成功', {
                    icon: 1,
                    time: 1000
                }, function () {
                    location.href = "../../pages/userManagement.html";
                });
            });
        });

    </script>

</body>

</html>